package newcoder_exp.justPractise;
import java.util.*;
import org.junit.*;
public class NC75 {
    public class Solution {
        public int[] FindNumsAppearOnce (int[] array) {
            //求异或
            int y = 0, len = array.length;
            for (int i = 0; i < len; i++) {
                y ^= array[i];
            }
            //找到y最低的1
            int d = 1;
            while ((d & y) == 0) {
                d <<= 1;
            }
            
            //按照d这一位是否为1分为两类数，分别对他们求异或
            int y2 = 0;
            y = 0;
             for (int i = 0; i < len; i++) {
                if ((array[i] & d) != 0) {
                    y ^= array[i];
                } else {
                    y2 ^= array[i];
                }
            }
            return y < y2 ? new int[]{y, y2} : new int[]{y2, y};
        }
    }


    @Test
    public void test() {
        Solution s = new Solution();
        int[] nums = new int[]{1,4,1,6};
        int[] res = s.FindNumsAppearOnce(nums);
    }
}
